<script type="text/javascript">

	$(function() {
		$('#catalog_${action_id}_tree').tree({
			url : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-datagrid.json?key=${key?default('')}'
		});
	});
	
	function catalog_${action_id}_add() {
		var node = $('#catalog_${action_id}_tree').tree('getSelected');
		var id = '';
		
		if(node){
			//id = node.id;
		}
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-form.htm?key=${key?default('')}&action_id=${action_id}&parent.id='+id,
			width : 300,
			height : 200,
			modal : true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#catalog_${action_id}_form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-add.json?key=${key?default('')}',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$("#catalog_${action_id}_tree").tree('reload');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
		
	}
	function catalog_${action_id}_edit() {
		var node = $('#catalog_${action_id}_tree').tree('getSelected');
		if(!node){
			$.messager.alert('',${action.getText('catalog.edit.warning')},'warning');
			return;
		}
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-edit.htm?key=${key?default('')}&action_id=${action_id}&id='+node.id+'&n='+Math.random(),
			width : 300,
			height : 200,
			modal : true,
			title : '${action.getText('form.edit.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#catalog_${action_id}_form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-update.json?key=${key?default('')}',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$("#catalog_${action_id}_tree").tree('reload');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	
	function catalog_${action_id}_delete() {
		var node = $('#catalog_${action_id}_tree').tree('getSelected');
		if(!node){
			$.messager.alert('',${action.getText('catalog.delete.warning')},'warning');
			return;
		}
		if (node) {
			$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('catalog.delete.ask')}', function(b) {
				if (b) {
					$.ajax({
						url : '${request.contextPath}${namespace?default('')}/mp/catalog/catalog-delete.json?key=${key?default('')}',
						data : {
							id : node.id
						},
						dataType : 'JSON',
						success : function(json) {
							$.messager.alert(json.title,json.msg,json.level);
							if(json.level!='error'){
								$("#catalog_${action_id}_tree").tree('reload');
							}
						}
					});
				}
			});
		}
	}

</script>
<div class="easyui-layout" style="width:100%;height:100%;" border="false"  >
	<div region="north" border="false" style="padding:5px;border:1px solid #ddd;" >
		<a href="javascript:;;" onclick="catalog_${action_id}_add();" class="easyui-linkbutton" data-options="iconCls:'icon-add'">${action.getProperty('net.esj.background.message','bg.datagrid.add')}</a>
		<a href="javascript:;;" onclick="catalog_${action_id}_edit();" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">${action.getProperty('net.esj.background.message','bg.datagrid.modify')}</a>
		<a href="javascript:;;" onclick="catalog_${action_id}_delete();" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>
	</div>
	<div region="center" border="false"  >
		<ul id="catalog_${action_id}_tree"></ul> 
	</div>
</div>